<!--
 * @Author: wangjh wangjiahui0710@163.com
 * @Date: 2024-06-11 11:33:49
 * @LastEditors: wangjh wangjiahui0710@163.com
 * @LastEditTime: 2024-07-26 16:52:02
 * @FilePath: \cip-admin\src\components\table-widget\table-widget.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<script lang="ts" setup>
import * as Cesium from "cesium";
import { useUserStore } from "@/stores/user";

defineOptions({ name: "VisionBox" });

const userStore = useUserStore();

onMounted(() => {
	Cesium.Ion.defaultAccessToken =
		"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJiMmViYTM0My1iODNjLTQ4ZDktOGM0Zi02Y2NlMGM5MWU4MjIiLCJpZCI6NDY1NTksImlhdCI6MTcxNTA3NTk4MH0.Vu8Kx1piGZog19BnmGqTyPtY_jZxhENgKPMluMoBASk";
	//自定义图层
	const provider = new Cesium.WebMapTileServiceImageryProvider({
		url: "https://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer",
		layer: "World_Imagery",
		style: "default",
		format: "image/png",
		tileMatrixSetID: "default028mm",
		maximumLevel: 18,
	});
	const Cartesian = Cesium.Cartesian3.fromDegrees(114.555, 30.5959, 1200);

	const skybox: any = import.meta.glob("../../assets/skybox/*.jpg", {
		eager: true,
		import: "default",
	});

	userStore.viewer = new Cesium.Viewer("cesiumContainer", {
		baseLayerPicker: false, // 图层选择器
		fullscreenButton: false, // 全屏按钮
		geocoder: false, // 右上角查询搜索
		infoBox: false, // 信息框
		homeButton: false, // home按钮
		sceneModePicker: false, // 3d 2d选择器
		selectionIndicator: false, //
		animation: false, // 左下角仪表
		timeline: false, // 时间轴
		navigationHelpButton: false, // 右上角帮助按钮
		shouldAnimate: true, // 允许动画
		skyBox: new Cesium.SkyBox({
			sources: {
				positiveX: skybox["../../assets/skybox/px.jpg"],
				negativeX: skybox["../../assets/skybox/nx.jpg"],
				positiveY: skybox["../../assets/skybox/py.jpg"],
				negativeY: skybox["../../assets/skybox/ny.jpg"],
				positiveZ: skybox["../../assets/skybox/pz.jpg"],
				negativeZ: skybox["../../assets/skybox/nz.jpg"],
			},
		}),
	});

	// 基础图层
	userStore.viewer.imageryLayers.add(new Cesium.ImageryLayer(provider, {}), 0);

	// 去除logo
	const creditContainer = userStore.viewer.cesiumWidget
		.creditContainer as HTMLDivElement;
	creditContainer.style.display = "none";

	//相机
	userStore.viewer.camera.setView({
		destination: Cartesian, //初始位置
		orientation: {
			//初始方向
			// heading: Cesium.Math.toRadians(-50), //初始方向
			// pitch: Cesium.Math.toRadians(-50), //初始方向
			// roll: Cesium.Math.toRadians(0),
		},
	});
});
</script>

<template>
	<div class="visionBox" id="cesiumContainer"></div>
</template>

<style lang="css">
.visionBox {
	width: 100%;
	height: 360px;
}
</style>
